<?php
Yii::import('adviser.controllers.project.ProjectFormAction');

class EditProjectFormAction extends ProjectFormAction {
	private $_project = null;
	
	public function getProject() {
		if ($this->_project == null) {
			$this->_project = Project::model()->findByPk($_GET['id']);
			if ($this->_project == null)
				throw new CHttpException(404, "Project #" . $_GET['id'] . " not found");
		}
		return $this->_project;
	}
	
	public function getOwner() {
		if ($this->getProject()->owner == null){
				throw new CHttpException(500, "Project #" . $_GET['id'] . " incomplete. No owner found.");
		}
		if(!isset($_POST['city_name']))
			$_POST['city_name'] = City::model()->findByPk($this->getProject()->owner->city_id)->label;
		return $this->getProject()->owner;
	}
}
